package com.itheima.service;

import com.itheima.dao.AccountDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * Description:
 *
 * @author codermao
 * @date 2023/11/5 11:27
 */
@Service
public class AccountServiceClass {

    @Autowired
    private AccountDao dao;

    @Transactional(
            propagation = Propagation.REQUIRED
    )
    public void s1(int outId, int inId, double money) {
        dao.outMoney(outId, money);
        //可能在转账过程中发生意外: 转出执行,转入还未执行
        int i = 1 / 0;
        dao.inMoney(inId, money);
    }

    @Transactional(
            propagation = Propagation.NOT_SUPPORTED
    )
    public void s2(int out, int in, double money) {
        dao.insertLog("转账操作由" + out + "到" + in + ",金额：" + money);
    }
}
